home *** CD-ROM | disk | FTP | other *** search
- /*
- CDSetDiscTitle - An XFCN to set the title of the disc.
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C CDSetDiscTitle.c
- link -sn Main=CDSetDiscTitle -sn STDIO=CDSetDiscTitle ∂
- -sn INTENV=CDSetDiscTitle -rt XFCN=42 ∂
- -m CDSetDiscTitle CDSetDiscTitle.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
- #include <ToolUtils.h>
-
- /* prototype definitions for functions */
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDSetDiscTitle
- *
- * Purpose: set the title of this disc.
- *
- * Returns: 0 if no error
- * whatever driver/io errors we might have encountered
- * otherwise.
- *
- * Side Effects:
- *
- * Description: We need 1 parameter: the new name for the disc.
- * Get the ioRefNum that we got from previously calling
- * CDOpen() by accessing the famous global.
- * call the driver with a READTOC call to find out
- * the lead-out time. This is a unique number for each
- * disc. Look in the System Folder for the file
- * "CD Remote Programs". Open that file, look at the
- * IndX resource to find out if we've got a matching
- * index. If we do, look up the STR# resource
- * referenced and modify that STR#'s first string to
- * be the new string. If we don't, create a new disc
- * entry and then modify the new STR#'s first string
- * to be the input string.
- *
- * Simple, really.
- *
- ************************************************************************/
- pascal void
- CDSetDiscTitle(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- OSErr result;
- short ioRefNum;
- short vRefNum;
- short resFile;
- Handle refHandle;
- Handle strHandle;
- short strListID;
- unsigned long discID;
- short numberOfTracks;
- Str255 title;
- Str255 newTitle;
- Str255 fileName;
- Str31 returnString;
-
- strcpy(title, "\p");
-
- /* Must be 1 parameter */
- if ((paramPtr->paramCount) != 1)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
- /* check that size of input parameter is less than 255 chars */
- if (strlen(*(paramPtr->params[0])) > 255)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum, vRefNum pair and split them out. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- vRefNum = ioRefNum >> 16;
- ioRefNum &= 0xFFFF;
-
- result = noErr;
-
- /* Only parameter is a disc title string */
- HandleToPString(paramPtr->params[0], (Ptr)newTitle);
-
- GetIndString(fileName, STR_ID, DRIVENAME);
- if (fileName == (Str255)0)
- result = ResError();
-
- if (result == noErr)
- {
- resFile = OpenSystemResFile(fileName);
- if (resFile == -1)
- result = ResError();
- }
-
- if (result == noErr)
- result = IDDisc(ioRefNum, &discID);
-
- if (result == noErr)
- result = GetNumberTracks(ioRefNum, &numberOfTracks);
-
- if (result == noErr)
- if (FindIndex(discID, &strListID) == false)
- result = AddDisc(discID, numberOfTracks);
-
- if (result == noErr)
- if (FindIndex(discID, &strListID) == false)
- result = fnfErr;
- /* something's badly wrong at this point */
- /* we've failed to create a valid program entry */
- /* and we're hosed */
-
- if (result == noErr)
- {
- GetIndString(title, strListID, 1);
- strHandle = Get1Resource('STR#', strListID);
- if (strHandle == nil)
- result = ResError();
- }
-
- if (result == noErr)
- Munger(strHandle, 2L, title, title[0]+1, newTitle, newTitle[0]+1);
-
- if (result == noErr)
- {
- ChangedResource(strHandle);
- result = ResError();
- }
- if (result == noErr)
- {
- WriteResource(strHandle);
- result = ResError();
- }
-
- CloseResFile(resFile);
-
- /* Convert result to string & return it */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-